#include "Piece.h"


void initialiserPiece(Piece* p, char t, char e, Coordonnee c){
	p->type=t;
	p->position = c;
	p->dejaJoue=false;
	p->tabDeplacement=malloc(sizeof(tabCoordonneeDyn));
	initialiserTabDyn(p->tabDeplacement);
	p->equipe=e;
}

void testamentPiece(Piece *p){
    p->type='v';
    p->position.posX = 0;
    p->position.posY = 0;
    testamentTabDyn(p->tabDeplacement);
}

Coordonnee getPosition(Piece *p){
	return p->position;
}

void setPosition(Piece *p, Coordonnee c){
	p->position=c;
}

bool getDejaJoue(Piece *p){
	return p->dejaJoue;
}

void setDejaJoue(Piece *p, bool b){
	p->dejaJoue=b;
}


char getEquipe(Piece *p){
	return p->equipe;
}


void setEquipe(Piece *p, char e){
	p->equipe=e;
}

void deplacementRoi(Piece *p) {
    int i,j;
    Coordonnee c;
    Coordonnee pos = p->position;
    for(i=pos.posX-1;i<=pos.posX+1;++i) {
        for(j=pos.posY-1;j<=pos.posY+1;++j) {               //IL L'A FAIT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            c.posX=i;
            c.posY=j;
            if(c.posX!=0 || c.posX!=9 || c.posY!=0 || c.posY!=9) {
                ajouterElementTabDyn(p->tabDeplacement, c);
            }
        }
    }
}

void deplacementFou(Piece *p) {
    int i,j;
    Coordonnee c;
    Coordonnee pos = p->position;
    for(i=pos.posX-1;i<=pos.posX+1;++i) {
        for(j=pos.posY-1;j<=pos.posY+1;++j) {
            c.posX=i;
            c.posY=j;
            if(c.posX!=0 || c.posX!=9 || c.posY!=0 || c.posY!=9) {
                ajouterElementTabDyn(p->tabDeplacement, c);
            }
        }
    }
    for(i=pos.posX-1;i<=pos.posX+1;++i) {
        for(j=pos.posY-1;j<=pos.posY+1;++j) {
            c.posX=i;
            c.posY=j;
            if(c.posX!=0 || c.posX!=9 || c.posY!=0 || c.posY!=9) {
                ajouterElementTabDyn(p->tabDeplacement, c);
            }
        }
    }
    for(i=pos.posX-1;i<=pos.posX+1;++i) {
        for(j=pos.posY-1;j<=pos.posY+1;++j) {
            c.posX=i;
            c.posY=j;
            if(c.posX!=0 || c.posX!=9 || c.posY!=0 || c.posY!=9) {
                ajouterElementTabDyn(p->tabDeplacement, c);
            }
        }
    }
    for(i=pos.posX-1;i<=pos.posX+1;++i) {
        for(j=pos.posY-1;j<=pos.posY+1;++j) {
            c.posX=i;
            c.posY=j;
            if(c.posX!=0 || c.posX!=9 || c.posY!=0 || c.posY!=9) {
                ajouterElementTabDyn(p->tabDeplacement, c);
            }
        }
    }

}


void deplacementTour(Piece *p) {

}

void deplacementDame(Piece *p) {
    deplacementFou(p);
    deplacementTour(p);
}

void deplacementCavalier(Piece *p){}

void deplacementPion(Piece *p){}

void definirDeplacement(Piece *piece){
    switch (piece->type) {
        case 'r':
            deplacementRoi(piece);
            break;
        case 'd':
            break;
        case 'f':
            break;
        case 'c':
            break;
        case 't':
            break;
        case 'p':
            break;
        default:
            break;
    }
}

